package com.lj.eduservice.controller;


import com.lj.eduservice.entity.Chapter;
import com.lj.eduservice.entity.dao.ChapterDao;
import com.lj.eduservice.service.ChapterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2021-05-06
 */
@RestController
@RequestMapping("/eduservice/chapter")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    @ApiOperation("根据课程id查询课程的章节和小节")
    @GetMapping("/getChapterAndVideoByCourseId")
    public List<ChapterDao> getChapterAndVideoByCourseId(String courseId){
        return chapterService.getChapterAndVideoByCourseId(courseId);
    }

    @ApiOperation("添加或更新章节")
    @PostMapping("/addOrUpdateChapter")
    public Boolean addOrUpdateChapter(@RequestBody ChapterDao chapterDao){
        Chapter chapter = new Chapter();
        BeanUtils.copyProperties(chapterDao,chapter);
        return chapterService.saveOrUpdate(chapter);
    }

    /**
     * @param chapterId
     * @return
     */
    @ApiOperation("根据章节id删除章节")
    @DeleteMapping("/deleteChapter/{chapterId}")
    public Boolean deleteChapter(@PathVariable("chapterId") String chapterId){
        return chapterService.deleteChapter(chapterId);
    }
}

